<template>
  <div class="detail">
    <p class="title">{{videoInfro.title}}</p>
    <div class="tips">
      <p>作者：{{creatorName}}</p>
      <p>上传时间：{{createDate}}</p>
      <!-- <p><i class="el-icon-video-play"></i> {{videoInfro.viewNum}}</p> -->
    </div>
    <div class="videoWrap">
      <video-player  class="video-player vjs-custom-skin" ref="videoPlayer"
      :playsinline="true"
      :options="playerOptions"
      @play="onPlayerPlay($event)"
      @pause="onPlayerPause($event)">
      </video-player>
    </div>
    <!-- <p class="infro-tit">视频详情</p> -->
    <div class="video-infro">
      <p><i class="el-icon-video-play"></i> {{videoInfro.viewNum}}</p>
      <ul>
        <li v-for="item in videoInfro.tags">{{item.name}}</li>
      </ul>
      <div class="infro-tit">视频议题</div>
      <div v-html="videoInfro.paragraph"></div>
    </div>
  </div>
</template>
<script>
import {getVideodetail} from "@/api/home.js";
import Detail from "../produce/detail.vue";
// import { videoPlayer } from 'vue-video-player';
// import 'video.js/dist/video-js.css';
export default {
    // components: {
    //   videoPlayer
    // },
    data() {
        return {
            id: "",
            videoInfro: "",
            creatorName: "",
            createDate: "",
            // 视频
            playerOptions: {
                autoplay: false,
                muted: false,
                loop: false,
                preload: "auto",
                language: "zh-CN",
                aspectRatio: "15:6",
                fluid: true,
                sources: [
                // {
                //   type: 'application/x-mpegURL', // 这里的种类支持很多种：基本视频格式、直播、流媒体等，具体可以参看git网址项目
                //   src: 'http://192.168.80.110:28101/vod/v1/test.mp4/index.m3u8' // url地址
                // }
                ],
                hls: true,
                poster: "",
                width: document.documentElement.clientWidth,
                notSupportedMessage: "此视频暂无法播放，请稍后再试",
                controlBar: {
                    timeDivider: true,
                    durationDisplay: true,
                    remainingTimeDisplay: false,
                    fullscreenToggle: true // 全屏按钮
                }
            }
        };
    },
    created() {
        this.id = this.$route.query.id;
        getVideodetail(this.id).then(res => {
            if (res.code == 200) {
                this.videoInfro = res.result;
                console.log(this.videoInfro, "3333");
                this.creatorName = this.videoInfro.user.creatorName;
                this.createDate = this.format(this.videoInfro.createDate);
                // console.log(this.createDate);
                this.playerOptions.poster = this.videoInfro.cover;
                const video = {
                    src: this.videoInfro.video,
                    type: "", //类型
                };
                this.playerOptions.sources.push(video);
            }
        });
    },
    computed: {
        player() {
            return this.$refs.videoPlayer.player;
        },
    },
    methods: {
        // 播放回调
        onPlayerPlay(player) {
            // console.log("player play!", player);
        },
        // 暂停回调
        onPlayerPause(player) {
            // console.log("player pause!", player);
        },
        // 转换时间戳为日期格式方法
        add(m) {
            return m < 10 ? "0" + m : m;
        },
        format(creatTime) {
            //shijianchuo是整数，否则要parseInt转换
            var time = new Date(creatTime);
            var y = time.getFullYear();
            var m = time.getMonth() + 1;
            var d = time.getDate();
            var h = time.getHours();
            var mm = time.getMinutes();
            var s = time.getSeconds();
            return (y +
                "-" +
                this.add(m) +
                "-" +
                this.add(d) +
                " " +
                this.add(h) +
                ":" +
                this.add(mm) +
                ":" +
                this.add(s));
        },
    },
    mounted() {
    },
    components: { Detail }
}
</script>

<style lang="less" scoped>
@import './../../../assets/style/edit.css';
.detail{
    width: 62.5%;
    height: 100%;
    display: table;
    background: #fff;
    padding: 20px 0 40px;
    margin: 20px auto 50px;
    font-size: 15px;
    .title{
      font-size: 30px;
      font-weight: 600;
      color: #191A24;
      line-height: 42px;
      text-align: center;
      margin-bottom: 8px;
    }
    .tips{
      font-size: 12px;
      font-weight: 400;
      color: #666666;
      line-height: 17px;
      display: flex;
      justify-content: center;
      // color: #acacac;
      p{
        margin-right: 25px;
      }
    }
    .videoWrap{
      width: 100%;
      // height: 500px;
      margin: 30px 0 15px;
      /deep/ video{
        object-fit: fill; // 消除播放器两边的黑色留白 （object-fit 知识详见下文拓展部分）
      }
      /deep/.video-js .vjs-big-play-button{
        border-width: 3px;
        border-color: rgb(255, 255, 255);
        border-style: solid;
        border-radius: 50%;
        width: 65px;
        height: 56px;
        line-height: 50px;
        background-color: rgba(0,0,0,0);
        position: absolute;
        top: 50%;
        bottom: 0;
        left: 0;
        right: 0;
        margin: auto;
      }
      /* 滚动条的样式 */
      /deep/.video-js .vjs-control-bar{
        background-color: rgba(43, 51, 63, 0);
      }
      /deep/.video-js .vjs-play-progress{
        background-color: rgb(238,191,0);
      }
      /deep/.video-js .vjs-load-progress div{
        background-color: rgb(255, 255, 255);
      }
      /deep/.vjs-poster{
        background-size: 100% 100%;
      }
    }
    .video-infro{
      padding: 0 15px;
      margin-top: 15px;
      p{
        font-size: 16px;
        font-weight: 400;
        color: #666666;
        line-height: 22px;
      }
      ul{
        display: flex;
        margin: 15px 0 20px;
        li{     
          background: #ECF1FF;
          font-size: 14px;
          font-weight: 400;
          color: #4370F3;
          line-height: 20px;
          padding: 3px 20px;
          margin-right: 20px;
          &:last-child{
            margin-right: 0;
          }
        }
      }

    }
    .infro-tit{
      font-size: 17px;
      font-weight: 400;
      color: #333333;
      line-height: 40px;
    }
    .infro-creator{
      display: flex;
      line-height: 32px; 
      margin: 10px 0;
      // color: #acacac;
      p:first-child{
        font-weight: bold;
        color: #000;
      }
    }
}
</style>